package main

import (
	"github.com/ngaut/log"
	"global/structs"
	"time"
)

type Manager struct {
	ctx *Context
}

func NewManager(ctx *Context) *Manager {
	return &Manager{
		ctx:     ctx,
	}
}

func (m *Manager) Serv() {
	for _, pair := range m.ctx.Data.CoinPair {
		go func(coinPair structs.CoinPair) {
			m.startWorker(coinPair)
		}(pair)
		time.Sleep(100 * time.Millisecond)
	}
}

func (m *Manager) startWorker(coinPair structs.CoinPair) {
	w := NewWorker(m.ctx, coinPair)
	w.Start()
	w.ctx.RegistWorker(coinPair.Name, w)
	log.Infof("start listening coin pair [%s] success ...", coinPair.Name)

	/*
	d := NewDepth(m.ctx, coinPair)
	d.Run()
	w.ctx.RegistDepth(coinPair.Name, d)
	*/
}
